<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<!--
Not Automatically generated, changed!:
$Id: script_ref_execution_model_filter_graph.htm,v 1.2 2010/11/28 18:47:26 wilbertd Exp $ 
-->
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Scripting reference - The script execution model - The filter graph</title>
<link rel="stylesheet" type="text/css" href="../avisynth.css">
</head>
<body>
<h2>The script execution model - The filter graph</h2>
<p>The final purpose of every AviSynth script is to create a filter graph that
can be used by the top-level AVI stream object (see previous section) to call
the filters needed for the creation of each specific frame that is requested by
the host video application.</p>
<p>This filter graph is <b>implicit</b> in the sense that it is not directly
available to script writers for querying or modification. However it is created
and built-up on each filter call that the script source code makes, using the
following rules:</p>
<ul>
  <li>Each filter -actually its resulting clip- links to <i>all</i> its source
    clips (those that it uses directly or indirectly for input).</li>
  <li>Source filters (such as <a href="corefilters/avisource.htm" title="AviSource">AviSource</a>)
    do not link to other clips. Their resulting clip is a leaf-node in the
    filter graph.</li>
  <li>Only filters -ie their resulting clips- that are linked by the final clip
    returned by the script are part of the filter graph. That is a clip is part
    of the filter graph only if there is a path that connects it with the final
    clip returned by the script.</li>
</ul>
<a name="An_example_of_a_filter_graph"></a>
<h3><span class="mw-headline">An example of a filter graph</span></h3>
<p>Consider the following script, which loads a clip, makes a simple levels
processing and muxes it with a custom sound track; then it overlays on top of it
another clip, along with its inverted image, as separate windows.</p>
<pre><a href="corefilters/avisource.htm">AviSource</a>(&quot;clip1.avi&quot;)
<a href="corefilters/levels.htm" title="Levels">Levels</a>(10, 1, 248, 0, 255)
aud = <a href="corefilters/avisource.htm" title="WavSource">WavSource</a>(&quot;mysoundtrack.wav&quot;)
<a href="corefilters/audiodub.htm" title="AudioDub">AudioDub</a>(last, aud)
ov = AviSource(&quot;clip2.avi&quot;)
ov1 = <a href="corefilters/resize.htm" title="Lanczos4Resize">Lanczos4Resize</a>(ov, 280, 210)
ov2 = ov1.<a href="corefilters/invert.htm" title="Invert">Invert</a>()
w = last.Width
h = last.Height
<a href="corefilters/overlay.htm" title="Overlay">Overlay</a>(ov1, x=w-280-40, y=40) # first clip is last
Overlay(ov2, x=w-280-40, y=h-210-40)</pre>
<p>The filter graph that results from the script code above is the following.</p>
<pre>AviSource(clip1) &lt;-- Levels &lt;--+
                               |
WavSource &lt;--------------------+-- AudioDub &lt;--+
                                               |
AviSource(clip2) &lt;-- Lanczos4Resize &lt;--+-------+-- Overlay &lt;--+          
                                       |                      |
                                       +-- Invert &lt;-----------+-- Overlay (filter graph's root)</pre>
<p>The root of the filter graph, that is the filter from which the host video
application requests video frames is the second <a href="corefilters/overlay.htm" title="Overlay">Overlay</a>
(the last line of the script).</p>
<hr>
<p>Back to the <a href="script_ref_execution_model.htm" title="The script execution model">script
execution model</a>.</p>
<p><kbd>$Date: 2010/11/28 18:47:26 $</kbd></p>
</body>
</html>
